package com.tianruan.dc.modules.sys.user.api;

import com.tianruan.dc.common.utils.response.VResponse;
import com.tianruan.dc.modules.sys.user.entity.db.RoleDO;
import com.tianruan.dc.modules.sys.user.entity.dto.RoleDTO;
import com.tianruan.dc.modules.sys.user.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/sys/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping
    public VResponse<List<RoleDO>> findRole(){
        return VResponse.success(roleService.list());
    }

    /**
     * 情况比较特殊，和普通角色列表数据结构不同
     * @return
     */
    @GetMapping("/special")
    public ResponseEntity listSpecialRole(){
        return ResponseEntity.ok(roleService.listRole());
    }

    @GetMapping("/{id}")
    public ResponseEntity getRole(@PathVariable("id")String id){
        return ResponseEntity.ok(roleService.getRoleById(id));
    }

    @PostMapping
    public ResponseEntity insert(@RequestBody RoleDTO roleDTO){
        return ResponseEntity.ok(roleService.insertRole(roleDTO));
    }

    @PutMapping("/{id}")
    public ResponseEntity update(@PathVariable("id")String id,
                                 @RequestBody RoleDTO roleDTO){
        return ResponseEntity.ok(roleService.updateRole(id, roleDTO));
    }
}
